package com.davesandoval.tpdroid;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DataBaseHelper extends SQLiteOpenHelper {

	private static String DB_NAME = "tpdroid_db";
	private static int DB_VERSION = 2;
	private static final String DATABASE_CREATE = "create table openSO (_id integer primary key"
			+ " autoincrement, soNumber text not null, accountName text not null,"
			+ " description text not null, priority text not null, reqDate text not null,"
			+ " status text not null, briefDescription text not null, workPerformed text not null,"
			+ " accountNumber text not null, soBlntask text not null, strRateBasis text not null);";

	public DataBaseHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE);

		db.execSQL("create table soLogs (_id integer primary key"
				+ " autoincrement, soNumber text not null, soReason text not null,"
				+ " logDetail text not null,"
				+ " startTime text not null, endTime text not null, startDate text not null,"
				+ " endDate text not null, newStatus text not null, chargeable text not null,"
				+ " billable text not null, copylc text not null, blntask text not null);");

		db.execSQL("create table accounts (_id integer primary key autoincrement, "
				+ "accountName text not null, contactName text not null, contactPhone "
				+ "text not null, address text not null, accountNumber text not null);");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(DataBaseHelper.class.getName(), "Upgrading database from version"
				+ oldVersion + " to " + newVersion
				+ ", which will destroy existing data.");
		db.execSQL("DROP TABLE IF EXISTS openSO");
		db.execSQL("DROP TABLE IF EXISTS soLogs");
		db.execSQL("DROP TABLE IF EXISTS accounts");
		onCreate(db);
	}
	
	public boolean isOpen() {
		return false;
	}

}